const Router = require('koa-router')
const free = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
  })

free.post('/free', async ctx => {
    // ctx.body = ''
    let {run_km, _time,run_speed,ka} = ctx.request.body;
    console.log("run_km",run_km);
    console.log("_time",_time);
    console.log("run_speed",run_speed);
    console.log("ka",ka);
    let insertContentPostgresql = `insert into free (run_km, _time,run_speed,ka) values ('${run_km}','${_time}', '${run_speed}', '${ka}')`;
    let content = await psql.query(insertContentPostgresql);

    if (content.rowCount > 0)
        ctx.body = {
            run_km:run_km,
             _time:_time,
             run_speed:run_speed,
             ka:ka
            
        };
})

module.exports = free